package com.chenfan.mcn.model.dto;

import cn.afterturn.easypoi.excel.annotation.Excel;
import com.chenfan.mcn.clients.privilege.SUserVo;
import com.chenfan.mcn.constant.NumberCst;
import com.chenfan.mcn.enums.StarTypeEnum;
import com.chenfan.mcn.enums.StudioPaymentEnum;
import com.chenfan.mcn.model.*;
import com.chenfan.mcn.utils.CommonUtil;
import lombok.Data;

import java.util.Map;

/**
 * OC红人-批量导入失败原因DTO
 * @author wulg
 * @date 2022-05-23
 **/
@Data
public class KocStarOutputDTO extends KocStarInputDTO {

    private static final long serialVersionUID = -6109624944585847343L;

    /**
     * 确认状态：0未确认1已确认
     */
    @Excel(name = "失败原因" , orderNum = "100")
    private String failedReason;

    /**
     * 唯一凭证
     */
    private String voucher;

    /**
     * 校验系统数据匹配
     * @param starMap
     * @param kocpmMap
     * @param userMap
     * @param platforNameMap
     */
    public void verifySysDataMatch(Map<String, StarBasicData> starMap, Map<String, Long> kocpmMap, Map<String, SUserVo> userMap, Map<String, String> platforNameMap, String separator) {
        if(starMap.containsKey(this.getVoucher())) {
            this.setFailedReason(CommonUtil.joinWith(separator,this.getFailedReason(), "红人已存在，请去页面编辑更新"));
        }
        if(!kocpmMap.containsKey(this.getKocpmName())) {
            this.setFailedReason(CommonUtil.joinWith(separator,this.getFailedReason(), "匹配不到启用中的参加项目"));
        }
        if(!userMap.containsKey(this.getStarAgentName())) {
            this.setFailedReason(CommonUtil.joinWith(separator,this.getFailedReason(), "匹配不到红人经纪人的系统账户"));
        } else {
            SUserVo sUser = userMap.get(this.getStarAgentName());
            if(sUser.getStatus().booleanValue()) {
                this.setFailedReason(CommonUtil.joinWith(separator,this.getFailedReason(), "红人经纪人非系统在职用户"));
            }
        }
        if(!platforNameMap.containsKey(this.getPlatformName())) {
            this.setFailedReason(CommonUtil.joinWith(separator,this.getFailedReason(), "匹配不到启用中的所在平台"));
        }
    }

    /**
     * 填充红人基础信息
     * @param starBasicData
     */
    public void fillStarBasicData(SUserVo sUserVo, StarBasicData starBasicData) {
        starBasicData.setStarAgentId(sUserVo.getUserId());
        starBasicData.setStarName(this.getStarName());
        starBasicData.setStarNickname(this.getStarNickname());
        starBasicData.setStarType(StarTypeEnum.KOC.getCode());
        starBasicData.setStarAgentName(this.getStarAgentName());
        starBasicData.setRemark(this.getRemark());
        starBasicData.setStarStatus(NumberCst.ZERO);
    }

    /**
     * 填充红人所在平台信息
     * @param starBasicData
     * @param platformId
     * @param starPlatformInfo
     */
    public void fillStarPlatformInfo(StarBasicData starBasicData, String platformId, StarPlatformInfo starPlatformInfo) {
        starPlatformInfo.setStarId(starBasicData.getId());
        starPlatformInfo.setPlatformId(platformId);
        starPlatformInfo.setPlatformName(this.getPlatformName());
        starPlatformInfo.setPlatNickName(starBasicData.getStarNickname());
        starPlatformInfo.setPlatformStatus(NumberCst.ZERO);
        starPlatformInfo.setIsAssessment(NumberCst.ONE);
    }

    /**
     * 填充红人红人收款账号信息
     * @param starBasicData
     * @param starAccountInfo
     */
    public void fillStarAccountInfo(StarBasicData starBasicData, StarAccountInfo starAccountInfo) {
        starAccountInfo.setStarId(starBasicData.getId());
        starAccountInfo.setAccountName(this.getAccountName());
        starAccountInfo.setAccountNumber(this.getAccountNumber());
        starAccountInfo.setAccountBank(this.getAccountBank());
        starAccountInfo.setAccountBranchBank(this.getAccountBranchBank());
        starAccountInfo.setAccountProvince(this.getAccountProvince());
        starAccountInfo.setAccountCity(this.getAccountCity());
        starAccountInfo.setAccountIdCard(this.getAccountIdCard());
        starAccountInfo.setAccountPhone(this.getAccountPhone());
        starAccountInfo.setStudioPayment(StudioPaymentEnum.getType(this.getStudioPayment()));
    }

    public void fillDocKocpmRedstar(StarBasicData starBasicData, Map<String, Long> kocpmMap, DocKocpmRedstar docKocpmRedstar) {
        //docKocpmRedstar.setStarPlatformInfoId();
    }
}
